#include "planner/property_enforcer.h"

#include <memory>
#include <vector>

#include "planner/physical_operators.h"
#include "planner/properties.h"
#include "planner/property.h"

namespace optimizer {

GroupExpression *PropertyEnforcer::EnforceProperty(GroupExpression *gexpr, Property *property) {
  input_gexpr_ = gexpr;
  property->Accept(this);
  return output_gexpr_;
}

void PropertyEnforcer::Visit(const PropertySort *prop) {
  std::vector<group_id_t> child_groups(1, input_gexpr_->GetGroupID());
  // TODO: memo order
  output_gexpr_ = new GroupExpression(std::make_shared<OrderBy>(), std::move(child_groups));
}

}  // namespace optimizer
